<template>
	<view class="wrapper">
		<view class="info-box">
			<input placeholder="Comment Name" v-model="commentName" class="input" />
			<input placeholder="Username/Email/Phone" v-model="userName" class="input" />
			<u-button text="Submit" class="btn" @click="handleAddFriends"></u-button>
		</view>
	</view>
</template>

<script>
import { querySearchUser } from '@/services/user'
import { queryAddFriend } from '@/services/friends'
	export default {
		data() {
			return {
				commentName: '',
				userName: ''
			};
		},
		methods: {
			// 添加好友
			async handleAddFriends () {
				const resp = await querySearchUser({
					userName: this.userName
				})
				console.log(resp);
				if (!resp.success) return
				this.handleSubmit(resp.result.data.userId)
			},
			async handleSubmit (friendId) {
				const resp = await queryAddFriend({
					friendId: friendId,
					commentName: this.commentName
				})
				console.log(resp);
				if (!resp.success) return
				uni.navigateTo({
          url: `/pages/chat/PersonalChat?targetId=${friendId}`
        })
			}
		},
	}
</script>

<style lang="scss" scoped>
.wrapper {
	box-sizing: border-box;
	padding: 40upx;
	.info-box {
		background: #FFFFFF;
		border-radius: 20upx;
		box-sizing: border-box;
		padding: 10upx 50upx 50upx;
		.input {
			margin-top: 40upx;
			width: 100%;
			height: 94upx;
			background: #F6F6F6;
			border-radius: 20upx;
			box-sizing: border-box;
			padding: 0 36upx;
			font-size: 26upx;
			font-weight: 400;
			color: #000000;
		}
		.btn {
			margin-top: 40upx;
			width: 100%;
			height: 90upx;
			background: #61BDB2;
			border-radius: 20upx;
			font-size: 30upx;
			font-weight: 400;
			color: #FFFEFE;
		}
	}
}
</style>
